#pragma once

#include "ActivityGroup.h"

#include "Activity.h"
#include "ActivityEdge.h"
#include "ActivityNode.h"

namespace uml {

void ActivityGroup::fromJson(const QJsonObject& json, QStringList& errorList) {
    if (json.isEmpty()) {
        return;
    }

    PartialElement::fromJson(json, errorList);
    JsonSerializable::fromJsonArray(containedEdges_, "containedEdges", json, errorList);
    JsonSerializable::fromJsonArray(containedNodes_, "containedNodes", json, errorList);
    inActivity_ = JsonSerializable::create<Activity>(json.value("inActivity"), errorList);

    JsonSerializable::fromJsonArray(subgroups_, "subgroups", json, errorList);
    superGroup_ = JsonSerializable::create<ActivityGroup>(json.value("superGroup"), errorList);

}

void ActivityGroup::toJson(QJsonObject& json) {
    PartialElement::toJson(json);
    JsonSerializable::toJsonArray(containedEdges_, "containedEdges", json);
    JsonSerializable::toJsonArray(containedNodes_, "containedNodes", json);
    if (inActivity_) {
        QJsonObject inActivity_json;
        inActivity_->toJson(inActivity_json);
        json.insert("inActivity", inActivity_json);
    }
    JsonSerializable::toJsonArray(subgroups_, "subgroups", json);
    if (superGroup_) {
        QJsonObject superGroup_json;
        superGroup_->toJson(superGroup_json);
        json.insert("superGroup", superGroup_json);
    }
}

/// <summary>
/// containingActivity
    /// The Activity that directly or indirectly contains this ActivityGroup.
/// </summary>
    /// <code>
    /// result = (if superGroup<>null then superGroup.containingActivity()
    /// else inActivity
    /// endif)
    /// </code>
shared_ptr<Activity> ActivityGroup::containingActivity() const
{
    return nullptr;
}

/// <summary>
/// containedEdges getter
/// ActivityEdges immediately contained in the ActivityGroup.
/// </summary>
vector<shared_ptr<ActivityEdge>>& ActivityGroup::containedEdges() {
    return containedEdges_;
}

/// <summary>
/// containedNodes getter
/// ActivityNodes immediately contained in the ActivityGroup.
/// </summary>
vector<shared_ptr<ActivityNode>>& ActivityGroup::containedNodes() {
    return containedNodes_;
}

/// <summary>
/// inActivity getter
/// The Activity containing the ActivityGroup, if it is directly owned by an
/// Activity.
/// </summary>
shared_ptr<Activity> ActivityGroup::inActivity() const {
    return inActivity_;
}

/// <summary>
/// inActivity setter
/// The Activity containing the ActivityGroup, if it is directly owned by an
/// Activity.
/// </summary>
void ActivityGroup::setInActivity(shared_ptr<Activity> value) {
    inActivity_ = value;
}

/// <summary>
/// subgroups getter
/// Other ActivityGroups immediately contained in this ActivityGroup.
/// </summary>
vector<shared_ptr<ActivityGroup>>& ActivityGroup::subgroups() {
    return subgroups_;
}

/// <summary>
/// superGroup getter
/// The ActivityGroup immediately containing this ActivityGroup, if it is directly
/// owned by another ActivityGroup.
/// </summary>
shared_ptr<ActivityGroup> ActivityGroup::superGroup() const {
    return superGroup_;
}

/// <summary>
/// superGroup setter
/// The ActivityGroup immediately containing this ActivityGroup, if it is directly
/// owned by another ActivityGroup.
/// </summary>
void ActivityGroup::setSuperGroup(shared_ptr<ActivityGroup> value) {
    superGroup_ = value;
}

} // namespace uml
